﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using FamilyJobsUI.DB1;
using FamilyJobsUI.Extensions;

namespace FamilyJobsUI.Controllers
{
    [RequireHttps]
    public class HomeController : Controller
    {
        private DB1.FamilyJobsDB db = new DB1.FamilyJobsDB();
        public ActionResult Index()
        {
            //return RedirectToAction("Headshots", "Users");
            var userModels = 
                from u in db.T_Users
                    .Where(a => a.user_PointEligible)
                join up in db.T_UserPoints on u.user_ID equals up.up_UserID 
                group new {u,up} by new { u.user_Name, u.user_Email, u.user_ID } into g
                select new Models.HomeIndexModel()
                {
                    user_ID = g.Key.user_ID,
                    user_Email= g.Key.user_Email, 
                    user_Name = g.Key.user_Name,
                    pointTotal =  g.Sum(a => a.up.up_Points)
                            //totalAmount = g.Max(a => (Int32.Parse(a.mAmount)))
                };

    //                group t by t.mBatchNo into g
    //                 select new { batchNo = g.Key, 
    //                              totalAmount = g.Max(a => (Int32.Parse(a.mAmount)))};
    //}

                    
            //var user1 = rawUsers.First().;
            

            //var userEditModelList = rawUsers                 .Project().To<Models.HomeIndexModel>();

            return View(userModels);
        }

        public ActionResult About()
        {
            ViewBag.Message = "Your application description page.";

            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }
    }
}